<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('教材借阅列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>教材ID：</label>
                                <input type="text" name="bookId"/>
                            </li>
                            <li>
                                <label>教材名称：</label>
                                <input type="text" name="bookName"/>
                            </li>
                            <li>
                                <label>借阅人：</label>
                                <input type="text" name="person"/>
                            </li>
                            <li>
                                <label>联系电话：</label>
                                <input type="text" name="phone"/>
                            </li>
                            <li>
                                <label>借阅日期：</label>
                                <input type="text" class="time-input" placeholder="请选择借阅日期" name="borrowDate"/>
                            </li>
                            <li>
                                <label>借阅数量：</label>
                                <input type="text" name="borrowMount"/>
                            </li>
                            <li>
                                <label>是否归还：</label>
                                <select name="still" th:with="type=${@dict.getType('borrow_still')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>归还日期：</label>
                                <input type="text" class="time-input" placeholder="请选择归还日期" name="stillDate"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
<!--                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:borrow:add">-->
<!--                    <i class="fa fa-plus"></i> 添加-->
<!--                </a>-->
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="book:borrow:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="book:borrow:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="book:borrow:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('book:borrow:edit')}]];
        var removeFlag = [[${@permission.hasPermi('book:borrow:remove')}]];
        var stillFlag = [[${@permission.hasPermi('book:borrow:still')}]];
        var datas = [[${@dict.getType('borrow_still')}]];
        var prefix = ctx + "book/borrow";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "教材借阅",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'bookId',
                    title: '教材ID'
                },
                {
                    field: 'bookName',
                    title: '教材名称'
                },
                {
                    field: 'person',
                    title: '借阅人'
                },
                {
                    field: 'phone',
                    title: '联系电话'
                },
                {
                    field: 'borrowDate',
                    title: '借阅日期'
                },
                {
                    field: 'borrowMount',
                    title: '借阅数量'
                },
                {
                    field: 'still',
                    title: '是否归还',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'stillDate',
                    title: '归还日期'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        if (row.still == 0) {
                            actions.push('<a style="margin-left: 3px;" class="btn btn-warning btn-xs ' + stillFlag + '" href="javascript:void(0)" onclick="listStill(\'' + row.id + '\')"><i class="fa fa-level-up"></i>归还</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function listStill(id){
            var listAddUrl = "/book/borrow" + "/still?id="+id;
            $.operate.get(listAddUrl, function (res) {
                $.form.reset();
            });
        }
    </script>
</body>
</html>